﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
namespace ERPForms
{
    public partial class ConsultareArhivaFrm : FrmRezumat
    {

        private TreeNode ConsultareArhiva=null;
        public ConsultareArhivaFrm(ModuleClass mInfo,TreeNode tn)
            : base(mInfo)
        {
            InitializeComponent();
            workConnString = mInfo.workConnectionString;
            ConsultareArhiva = tn;
        }

        private void ConsultareArhivaFrm_Load(object sender, EventArgs e)
        {
            SetCurentUnit(ModuleInfo.CodUnitate);
            if (!EsteArhiva())
                AddButton("Deschide", global::ERPStudio.Properties.Resources.salvare1, DeschideArhiva, ToolStripItemAlignment.Right, true);

        }

        private void DeschideArhiva(object sender, EventArgs e)
        {
            //dscModule.AnArhiva = "2009";
            MessageBox.Show("Atentie! Se vor inchide toate machetele. Salvati datele, acolo unde este cazul!",
                            "Info",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
            foreach (StudioForm fChild in MdiParent.MdiChildren)
            {
                if (fChild != this)
                    fChild.Close();
            }
            if (this.arhiveDGV.CurrentRow == null || this.arhiveDGV.CurrentRow.IsNewRow)
            {
                
                this.DialogResult = DialogResult.None;
                MessageBox.Show("Va rugam selectati un rand existent in baza de date!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ToolStripMenuItem mn_Consultare_Arhiva = null;
            ToolStripMenuItem mn_Parametrizare_Modul = null;

            ModuleInfo.AnArhiva = ((DataGridViewRow)this.arhiveDGV.CurrentRow).Cells[AnulColumn.Index].Value.ToString();
            SetArhiva(ModuleInfo.AnArhiva);
            if (ModuleInfo.ModuleName == "balcon")
            {
                mn_Consultare_Arhiva = ModuleInfo.FindMenuItem(ModuleInfo.menuMain, "Consultare Arhiva");
                mn_Parametrizare_Modul = ModuleInfo.FindMenuItem(ModuleInfo.menuMain, "Setari");

                if (mn_Consultare_Arhiva != null)
                    mn_Consultare_Arhiva.Text = "Perioada Curenta";
                if (mn_Parametrizare_Modul != null)
                    mn_Parametrizare_Modul.Visible = false;
            }
            Close();
            if (ConsultareArhiva != null)
                ConsultareArhiva.Text = "Revenire perioada curenta";
        }
        override public void SetCurentUnit(short vCodUnitate)
        {
            ModuleInfo.CodUnitate = vCodUnitate;
            this.arhiveTableAdapter.Connection = DeschideConexiune(workConnString);
            if(ModuleInfo.ModuleName=="balcon")
                this.arhiveTableAdapter.FillForBalCon(this.eSRPDataSet.Arhive, ModuleInfo.CodUnitate);
            else if (ModuleInfo.ModuleName == "fares")
                this.arhiveTableAdapter.FillForFares(this.eSRPDataSet.Arhive, ModuleInfo.CodUnitate);
            else if (ModuleInfo.ModuleName == "resuma")
            {
                this.arhiveTableAdapter.FillForResUma(this.eSRPDataSet.Arhive, ModuleInfo.CodUnitate);
                LunaColumn.Visible = true;
            }
            else
                this.arhiveTableAdapter.Fill(this.eSRPDataSet.Arhive, ModuleInfo.CodUnitate);
            InchideConexiune(this.arhiveTableAdapter.Connection);

        }
        override public void SetCurentMonth(short vCodUnitate)
        {
           // Setup(conn);
        }
        /// <summary>
        /// cand se apasa enter, controlul activ este luna, anul
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        override public void toolStripLabelAnLuna_Click(object sender, EventArgs e)
        {

        }

    }
}
